import { Injectable } from '@nestjs/common';
import config from 'src/config/config';
@Injectable()
export class CookieService {
    set(res, key: string, value: any, maxAge?: number) {
        maxAge = maxAge || config.cookie.maxAge;
        res.cookie(key, JSON.stringify(value), { maxAge, httpOnly: true, signed: true });
    }
    get(req, key: string) {
        try {
            const value = req.signedCookies[key];
            if (value) return JSON.parse(value);
            return null;
        } catch (error) {
            return null;
        }
    }
}
